package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.studentDao;
import com.itheima.edu.info.manager.domain.Student;

public class studentService {
    //创建studentDao库管
    private studentDao StudentDao =new studentDao();
    public boolean addStudent(Student stu) {

        return StudentDao.addStudent(stu);



    }

    public boolean isExists(String id) {

        Student[] stus=StudentDao.findAllStudent();
// 假设ID不存在
        boolean exists=false;
        for (int i = 0; i < stus.length; i++) {
            Student student=stus[i];
            if (student!=null &&student.getId().equals(id)){
                exists=true;
                break;
            }

        }
        return exists;
    }

    public Student[] findAllStudent() {
        //调用库管对象的findall方法 获取学生对象数组
        Student[] allStudent =StudentDao.findAllStudent();
        //判断数组中是否有学生信息（有返回地址，没有：返回null）
        //数组中只要有一个不是null的元素 就代表有学生信息
        boolean flag=false;
        for (int i = 0; i < allStudent.length; i++) {
            Student stu=allStudent[i];
            if (stu!=null){
                flag=true;
                break;
            }

        }
      if (flag){
          return allStudent;
      }else{
          return null;
      }
    }

    public void deletestudent(String deleteid) {
        StudentDao.deletestudent(deleteid);
    }

    public void updateStudent(String updeteid, Student newstu) {
        StudentDao.updateStudent(updeteid,newstu);
    }
}
